package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.module.base.business.AccountBusiness;
import com.gnerv.battle.boot.module.base.model.dto.AccountCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.AccountDTO;
import com.gnerv.battle.boot.module.base.model.dto.AccountRoleDTO;
import com.gnerv.battle.boot.module.base.model.dto.AccountUpdateDTO;
import com.gnerv.battle.boot.common.base.annotation.log.LogController;
import com.gnerv.battle.boot.common.base.annotation.log.LogOperate;
import com.gnerv.battle.boot.common.base.model.RestResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/account")
public class AccountController {

    private final AccountBusiness accountBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody AccountCreateDTO accountCreateDTO) {
        return accountBusiness.create(accountCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return accountBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody AccountUpdateDTO accountUpdateDTO) {
        return accountBusiness.updateByUkId(accountUpdateDTO);
    }

    @PutMapping(value = "role")
    public RestResult<Void> updateRoleByUkId(@RequestBody AccountRoleDTO accountRoleDTO) {
        return accountBusiness.updateRoleByUkId(accountRoleDTO);
    }

    @GetMapping(value = "")
    public RestResult<AccountDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return accountBusiness.selectByUkId(ukId);
    }

    @LogController(value = "查询用户", logOperate = LogOperate.SELECT)
    @GetMapping(value = "list")
    public RestResult<List<AccountDTO>> listByUsername(@RequestParam(required = false, value = "username") String username,
                                                       @RequestParam(required = false, value = "page") Integer page,
                                                       @RequestParam(required = false, value = "size") Integer size) {
        return accountBusiness.listByUsername(username, page, size);
    }

    @GetMapping(value = "list/role")
    public RestResult<List<AccountDTO>> listByRoleUkId(@RequestParam(value = "roleUkId") String roleUkId) {
        return accountBusiness.listByRoleUkId(roleUkId);
    }


    @GetMapping(value = "list/org")
    public RestResult<List<AccountDTO>> listByOrgUkId(@RequestParam(value = "orgUkId") String orgUkId) {
        return accountBusiness.listByOrgUkId(orgUkId);
    }

}
